package com.chenjia.proto.converter.utils;

import com.google.protobuf.Message;
import com.chenjia.proto.converter.annotation.ProtoClass;

/**
 * Utilities for extract data stored in the annotations.
 *
 * @author jsjem
 * @author Roman Gushel
 */
public class AnnotationUtils {

    /**
     * Find {@link ProtoClass} related to {@code protobufClass}.
     *
     * @param domainClass   Domain class annotated by {@link ProtoClass}.
     * @param protobufClass Related Protobuf message class.
     * @return Instance of {@link ProtoClass} or null if there is
     * no relation between {@code domainClass} and {@code protobufClass}.
     */
    public static ProtoClass findProtoClass(final Class<?> domainClass, final Class<? extends Message> protobufClass) {
        if (domainClass.isAnnotationPresent(ProtoClass.class)) {
            return domainClass.getAnnotation(ProtoClass.class);
        }
        return null;
    }
}
